package org.itzheng.myrxframe.bugly;

import android.content.Intent;

import com.tencent.bugly.beta.UpgradeInfo;
import com.tencent.bugly.beta.upgrade.UpgradeListener;

import org.itzheng.and.baseutils.log.LogHelper;
import org.itzheng.and.baseutils.ui.UIUtils;

/**
 * 更新监听，收到策略时回调
 */
public class BuglyUpgradeListener implements UpgradeListener {
    private static final String TAG = "BuglyUpgradeListener";

    /**
     * 接收到更新策略
     *
     * @param ret       0:正常 －1:请求失败
     * @param strategy  更新策略
     * @param isManual  true:手动请求 false:自动请求
     * @param isSilence true:不弹窗 false:弹窗
     * @return 是否放弃SDK处理此策略，true:SDK将不会弹窗，策略交由app自己处理
     */
    public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean isSilence) {
        LogHelper.w(TAG, "onUpgrade: ret " + ret + " isManual " + isManual + " isSilence " + isSilence);
        if (strategy != null) {
            Intent i = new Intent();
            i.setClass(UIUtils.getContext(), UpgradeActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            UIUtils.startActivity(i);
        } else {
            UIUtils.showToast("没有更新");
        }
    }
}
